/*
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at 
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  
 */

using System;
using java = biz.ritter.javapi;

namespace org.apache.commons.collections.collection
{

    /**
     * Decorates another <code>Collection</code> to provide additional behaviour.
     * <p>
     * Each method call made on this <code>Collection</code> is forwarded to the
     * decorated <code>Collection</code>. This class is used as a framework on which
     * to build to extensions such as synchronized and unmodifiable behaviour. The
     * main advantage of decoration is that one decorator can wrap any implementation
     * of <code>Collection</code>, whereas sub-classing requires a new class to be
     * written for each implementation.
     * <p>
     * This implementation does not perform any special processing with
     * {@link #iterator()}. Instead it simply returns the value from the 
     * wrapped collection. This may be undesirable, for example if you are trying
     * to write an unmodifiable implementation it might provide a loophole.
     *
     * @since Commons Collections 3.0
     * @version $Revision$ $Date$
     * 
     * @author Stephen Colebourne
     * @author Paul Jack
     */
    public abstract class AbstractCollectionDecorator : java.util.Collection<Object>
    {

        /** The collection being decorated */
        protected internal java.util.Collection<Object> collection;

        /**
         * Constructor only used in deserialization, do not use otherwise.
         * @since Commons Collections 3.1
         */
        protected AbstractCollectionDecorator()
            : base()
        {
        }

        /**
         * Constructor that wraps (not copies).
         * 
         * @param coll  the collection to decorate, must not be null
         * @throws IllegalArgumentException if the collection is null
         */
        protected AbstractCollectionDecorator(java.util.Collection<Object> coll)
        {
            if (coll == null)
            {
                throw new java.lang.IllegalArgumentException("Collection must not be null");
            }
            this.collection = coll;
        }

        /**
         * Gets the collection being decorated.
         * 
         * @return the decorated collection
         */
        protected virtual java.util.Collection<Object> getCollection()
        {
            return collection;
        }

        //-----------------------------------------------------------------------
        public virtual bool add(Object obj)
        {
            return collection.add(obj);
        }

        public virtual bool addAll(java.util.Collection<Object> coll)
        {
            return collection.addAll(coll);
        }

        public virtual void clear()
        {
            collection.clear();
        }

        public virtual bool contains(Object obj)
        {
            return collection.contains(obj);
        }

        public virtual bool isEmpty()
        {
            return collection.isEmpty();
        }

        public virtual java.util.Iterator<Object> iterator()
        {
            return collection.iterator();
        }

        public virtual bool remove(Object obj)
        {
            return collection.remove(obj);
        }

        public virtual int size()
        {
            return collection.size();
        }

        public virtual Object[] toArray()
        {
            return collection.toArray();
        }

        public virtual Object[] toArray<Object>(Object[] obj)
        {
            return collection.toArray(obj);
        }

        public virtual bool containsAll(java.util.Collection<Object> coll)
        {
            return collection.containsAll(coll);
        }

        public virtual bool removeAll(java.util.Collection<Object> coll)
        {
            return collection.removeAll(coll);
        }

        public virtual bool retainAll(java.util.Collection<Object> coll)
        {
            return collection.retainAll(coll);
        }

        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return true;
            }
            return collection.equals(obj);
        }

        public override int GetHashCode()
        {
            return collection.GetHashCode();
        }

        public override String ToString()
        {
            return collection.ToString();
        }
    }
}